<extend name="Base/common"/>
<!--<script type="text/javascript" src="/SG_Shopwechat/Public/Home/js/iscroll.js"></script>-->
<block name="TITLE"><title>今日采价</title></block>
<block name="body" >
    <header data-am-widget="header" class="am-header am-header-default am-header-fixed">
        <div class="am-header-left am-header-nav">

        </div>
        <h1 class="am-header-title">
            <a href="#title-link" class="">
                &nbsp;{$title}
            </a>
        </h1>

    </header>
    <div class="am-form am-list-news-bd "  style="font-size: 15px;" >
       <form action="{:U('newreport')}" method="post" class="am-form"  data-am-validator>
           <div class="am-margin-left">
               <div class="am-list-item">
                   <div class="am-form-group">
                       <label for="market_name">今日采购商家</label>
                       <input type="text" style="border-radius: 12px;" class="" id="market_name" name="market_name" required/>
                   </div>
               </div>
           </div>
            <hr data-am-widget="divider" style="" class="am-divider am-divider-default" />
            <div class="am-margin-left">
                <div class="am-form-group am-form-file">
                    <button type="button" class="am-btn am-btn-danger am-btn-sm">
                        <i class="am-icon-cloud-upload"></i>
                        上传照片
                    </button>
                    <input id="doc-form-file" name="qiniu_file" type="file" class="uploadbtn" />
                    <span class="am-text-sm" style="color:#b2b2b2">(图片要能看清商品标签)</span>
                </div>
                <img src="__PUBLIC__/Admin/images/nopic.png" id="upimg" class="am-img-responsive" style="width: 50%;" />
                <input type="hidden"  name="img" id="img" class="am-input-sm am-margin-top-xs" style="border-radius: 12px;" required/>
            </div>
            <div class="am-g">
                <div class="am-u-sm-8">
                    <input type="text" placeholder="商品名称" name="pname" id="pname" class="am-input-sm am-margin-top-xs" style="border-radius: 12px;" required/>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-8 am-margin-top-xs col-2-input">
                    <input type="text" placeholder="商品规格" name="spec" id="spec" class="am-input-sm " style="border-radius: 12px;" required/>
                    <input type="text" placeholder="商品价格" name="price" id="price" class="am-input-sm am-margin-top-xs" style="border-radius: 12px;" required/>
                </div>
                <div class="am-u-sm-4 am-margin-top-xs">
                    <button type="submit" id="submitbtn" class="submit-btn am-btn am-btn-primary am-radius" >提交</button>
                </div>
            </div>
       </form>
    </div>
    <div class="am-modal am-modal-loading am-modal-no-btn"  tabindex="-1" id="icon-alert">
        <div class="am-modal-dialog " style="background: rgba(255,255,255,0);">
            <div class="am-modal-hd" style="color: #FFF;"><i class="am-icon-spinner am-icon-pulse"></i>图片上传中...</div>
        </div>
    </div>
    <div class="am-modal am-modal-alert" tabindex="-1" id="error-alert">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">提示</div>
            <div class="am-modal-bd">
                请先上传图片
            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn">确定</span>
            </div>
        </div>
    </div>
</block>
<block name="script">

    <script>
        $(function(){
            var loading = $('#icon-alert');
            var error = $('#error-alert');
            $(".submit-btn").css("height",$(".col-2-input").height());
            $(".submit-btn").css("width",20+$(".col-2-input").height());
            $(".uploadbtn").change(function(){
                loading.modal()
                var url = '{:U('uploadOne')}';
                lrz(this.files[0], {width: 800}).then(function (rst){
                    console.log(rst.base64);
                    $.ajax({
                        type: "POST",
                        url:url,
                        data:{data:rst.base64},
                        async: false,
                        error: function(request) {
                            loading.modal("close")
                            console.log(request);
                        },
                        success: function(data) {
                            $("#upimg").attr("src",data);
                            $("#img").val(data);
                            loading.modal("close")
                            console.log(data);
                        }
                    });
                });
            });
            $("#submitbtn").click(function(){
                if($('#img').val()==""||$('#img').val()==undefined){
                    error.modal();
                    return false;
                }
            });
//            $("#path").change(function(){
//                lrz(this.files[0], {width: 800}).then(function (rst){
//                    var url = '{:U('uploadOnebase')}';
//                    $.ajax({
//                        type: "POST",
//                        url:url,
//                        data:{data:rst.base64},
//                        async: false,
//                        error: function(request) {
//                            console.log(request);
//                        },
//                        success: function(data) {
//                            console.log(data);
//                        }
//                    });
//                })
////            })
        })
    </script>
</block>
